package com.design.twords.adatper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.design.twords.R;
import com.design.twords.database.RelWord_all;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Create by Alen
 * Time:  15:53
 */
public class RelWordAdapter extends RecyclerView.Adapter<RelWordAdapter.MyViewHolder>{

    private LayoutInflater myInflater;
    private Context context;
    private List<RelWord_all> relWords;
    private int viewId;
    private String booktype;

    public RelWordAdapter(Context context, List<RelWord_all> relWords, int viewId, String booktype) {
        this.myInflater = LayoutInflater.from(context);
        this.context = context;
        this.relWords = relWords;
        this.viewId = viewId;
        this.booktype = booktype;
    }

    public void setRelWords(List<RelWord_all> relWords) {
        this.relWords = relWords;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(myInflater.inflate(viewId, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        RelWord_all word_all = relWords.get(position);
        holder.relword_type.setText(word_all.getWrodType());
        holder.relword_content.setText(word_all.getWord());
        holder.relword_trans.setText(word_all.getTran());

    }

    @Override
    public int getItemCount() {
        return relWords.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView relword_type, relword_content, relword_trans;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            relword_type = itemView.findViewById(R.id.relword_type);
            relword_content = itemView.findViewById(R.id.relword_content);
            relword_trans = itemView.findViewById(R.id.relword_trans);
        }
    }
}
